package com.fit.piris.entities.user.fanpage;

import java.util.Date;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fit.piris.entities.fanpage.FanPage;
import com.fit.piris.entities.user.User;

@Entity
@Table(name = "user_fan_pages")
@AssociationOverrides({
		@AssociationOverride(name = "pk.user", joinColumns = @JoinColumn(name = "user_id")),
		@AssociationOverride(name = "pk.fanPage", joinColumns = @JoinColumn(name = "fan_page_id")) })
public class UserFanPage {

	@EmbeddedId
	private UserFanPagePk pk = new UserFanPagePk();
	@Column(name = "date_unrol")
	private Date dateUnrol;

	public UserFanPagePk getPk() {
		return pk;
	}

	public void setPk(UserFanPagePk pk) {
		this.pk = pk;
	}

	public Date getDateUnrol() {
		return dateUnrol;
	}

	public void setDateUnrol(Date dateUnrol) {
		this.dateUnrol = dateUnrol;
	}

	public void setUser(User user) {
		getPk().setUser(user);
	}

	@Transient
	public User getUser() {
		return getPk().getUser();
	}

	public void setFanPage(FanPage fanPage) {
		getPk().setFanPage(fanPage);
	}

	@Transient
	public FanPage getFanPage() {
		return getPk().getFanPage();
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		UserFanPage that = (UserFanPage) o;

		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;

		return true;
	}

}
